package job.jingdong;

import java.util.*;

/**
 * @program: LeetCodePractice
 * @description:
 * @author: WongKee
 * @create: 2020-08-27 19:34
 * 求2  3  5 组合的第N大的数
 **/
public class DiNthShu {

    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        int n=scanner.nextInt();
        int[] data={2,3,5};
        List<String> list=new ArrayList<>();
        bfs(list,data,n);
  /*      for (int i=0;i<n;i++){
            System.out.println(list.get(i));
        }*/
        System.out.println(list.get(n-1));

    }

    public static void bfs(List<String> list,int[] data,int n){
        Queue<String> queue=new ArrayDeque<>();
        int len=data.length;
        for(int i=0;i<len;i++){
            queue.add(data[i]+"");
        }

        while(!queue.isEmpty()){
            if(list.size()>n)
                return;
            int size=queue.size();
            for(int i=0;i<size;i++){
                String tmp=queue.poll();
                list.add(tmp);
                for(int j=0;j<len;j++){
                    queue.add(tmp+data[j]);
                }
            }
        }
    }
}
